import axios from '../../axios/index'

export interface userPageInterface {
    account?: string
    name?: string
    userType?: number //用户类型(1、员工，2、外部用户)
    disable?: number //	0.可用；1.禁用
    roleId?: number
    current?: number
    size?: number
}

//用户分页查询
export const userPage = (params: userPageInterface) => {
    return axios({
        method: 'get',
        url: '/api/user/manage/users',
        params
    })
}

export interface userOperation {
    account: string
    disable: number
    name: string
    password?: string
    userType?: number
    id?: string
}

//创建用户
export const createUser = (data: userOperation) => {
    return axios({
        method: 'post',
        url: '/api/user/manage/users',
        data
    })
}
//更新用户
export const updateUser = (data: userOperation) => {
    return axios({
        method: 'put',
        url: '/api/user/manage/users',
        data
    })
}

//分配角色
export const allocationRole = (userId: string, roleIds: string[]) => {
    return axios({
        method: 'put',
        url: '/api/user/manage/users/assign-roles',
        data: {
            userId,
            roleIds
        }
    })
}

//查询用户列表
export const userList = (params: userPageInterface) => {
    return axios({
        method: 'get',
        url: '/api/user/manage/users/list',
        params
    })
}
//重置密码
export const userResetPassword = (password: string, id: string) => {
    return axios({
        method: 'put',
        url: '/api/user/manage/users/reset-pwd',
        data: {
            password,
            id
        }
    })
}
//用户启用禁用
export const userDisable = (id: string, disable: number) => {
    return axios({
        method: 'put',
        url: '/api/user/manage/users/status',
        data: {
            id,
            disable
        }
    })
}
//查询用户信息
export const userInfo = (id: string) => {
    return axios({
        method: 'get',
        url: `/api/user/manage/users/${id}`
    })
}
